#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct node
{
    int val;
    struct node *next;
};
typedef struct node node;

node *list_init()
{
    node *head = (node *)malloc(sizeof(node));
    if (head == NULL)
        exit(1);
    head->val = -1;
    return head;
}

void list_destroy(node *head)
{
    node *p;
    while (head != NULL) {
        p = head;
        head = head->next;
        free(p);
    }
}

void dump(node *head)
{
    int i = 0;
    printf("DUMP: ");
    while (head)
    {
        printf("(%02d)%02d ", i, head->val);
        i++, head = head->next;
    }
    printf("\n");
}

node * list_locate(node *head, int idx)
{
    int i = 0;;
    for (i = 0; i < idx; i++)
    {
        if (head == NULL)
            return NULL;
        head = head->next;
    }
    return head;
}

int list_insert(node *head, int idx, int val)
{
    node *pos = list_locate(head, idx);
    if (pos == NULL)
        return 0;
    node *x = (node *)malloc(sizeof(node));
    if (x == NULL)
        exit(1);
    x->val = val;
    x->next = pos->next;
    pos->next = x;
    return 1;
}

int list_modify(node *head, int idx, int val)
{
    node *pos = list_locate(head, idx);
    if (pos == NULL)
        return 0;
    pos->val = val;
    return 1;
}

int list_remove(node *head, int idx)
{
    //找到要删除节点的上一个
    node *pos = list_locate(head, idx - 1);
    if (pos == NULL || pos->next == NULL)
        return 0;
    node *q = pos->next; //记录要删除节点的指针到q
    pos->next = q->next; //将q的上个节点链接到q的下个节点
    free(q); //释放要删除节点的指针
    return 1;
}

int main()
{
    int op, idx, val;
    node *list = list_init(), *query = NULL;
    while (scanf("%d%d%d", &op, &idx, &val) == 3)
    {
        switch(op)
        {
            case 1: 
                list_insert(list, idx, val);
                break;
            case 2: 
                list_modify(list, idx, val);
                break;
            case 3: 
                list_remove(list, idx);
                break;
            case 4: 
                query = list_locate(list, idx);
                if (query != NULL)
                    printf("%d\n", query->val);
                break;
        }
        //dump(list);
    }
    list_destroy(list);
    return 0;
}
